package com.sskj.fabi.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.fabi.bean.OrderDetailBean;
import com.sskj.fabi.http.HttpConfig;
import com.sskj.fabi.ui.activity.OrderRecordDetailActivity;
import com.sskj.lib.http.JsonCallBack;


public class OrderRecordDetailActivityPresenter extends BasePresenter<OrderRecordDetailActivity> {
    public void getOrderInfo(String orderNum, boolean isLoad) {

        httpService.getOrderRecordInfo(orderNum)
                .execute(new JsonCallBack<HttpData<OrderDetailBean>>(this, isLoad) {

                    @Override
                    public void onSuccess(Response<HttpData<OrderDetailBean>> response) {
                        HttpData<OrderDetailBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateUI(httpData.getData());
                        }
                    }
                });
    }


    /**
     * 标记已付款
     *
     * @param orderNum
     */
    public void markPay(String orderNum) {
        httpService.markPay(orderNum)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 取消订单
     *
     * @param orderNum
     */
    public void cancelOrder(String orderNum) {
        httpService.cancelOrder(orderNum)
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 账单申诉
     *
     * @param orderNum
     */
    public void allegeOrder(String orderNum, String refer, String shop_account, String ss_type, String ss_reason) {
        httpService.allegeOrder(orderNum, refer, shop_account, ss_type, ss_reason)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getStatus() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 确认放行
     *
     * @param orderNum
     * @param pwd
     */
    public void letGo(String orderNum, String pwd) {
        httpService.letGo(orderNum, pwd)
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getStatus() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }
}
